package a_aa_amainpackage.qiye_test.address;/*
 *项目名: o2odata_commend
 *文件名: createforeigntable
 *创建者: hancongcong
 *创建时间:2019/8/15 18:12
 *描述: TODO
 */

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Properties;

public class createforeigntable {
    /**
     * 需要更换的东西=================================================
     * 店铺:
     * plat = {"dazhongdp","elm","jd","meituan","meituan_tg","pinduoduo","suning","taobao","tmall","txd"};
     * paths = "/dws-data/g_shop/2020/4/"
     * schem = "zf_test"
     * String path = obs + paths + pla +  "/" ;
     * String fordername = paths + pla +  "/";
     * CREATE foreign TABLE "${schem}"."g_2020_${plat}_shop_${month}"
     *
     * 小平台单品：
     * plat = {"secoo","kaola","jumei","miya","beibei","yunji","dangdang","guomei"};
     * paths = "/dws-data/split/split_data/2020/"
     * schem = "test_liu"
     * String path = obs + paths + pla +  "/4/" ;
     * String fordername = paths + pla +  "/4/";
     * CREATE foreign TABLE "${schem}"."g_2020_${plat}_${month}"
     */

    /****************************************************************************************/

    //店铺:
//    public static String[] plat = {"dazhongdp","elm","jd","meituan","meituan_tg","pinduoduo","suning","taobao","tmall","txd"};
    //,"elm"
//    public static String[] plat = {"jd"};


//    public static String[] plat = {"secoo","kaola","jumei","miya","beibei","yunji","dangdang","guomei"};
//    public static String[] plat = {"aomygad"};
//    public static String[] plat = {"aomygad","yangmatou"};



//            "dazhongdp","meituan_tg"
//            "jumei"
//            "aomygad","yangmatou"
//            "elm","tmall","meituan"
//            "elm","tmall","meituan"
//            "dzdp","jd","meituan_tg","suning","elm","tmall","meituan"
//            "taobao"
//
//    };
//    "elm","meituan","tmall","hmxs"

//    public static String paths = "/dws-data/split/split_data/2021/";
//    public static String paths = "/o2o-dataproces-group/zsc/address_table/";
//    public static String paths = "/dws-data/g_shop/2021/2/";

    //小平台单品：
//    public static String[] plat = {"secoo","kaola","jumei","miya","beibei","yunji","dangdang","guomei"};
//    public static String[] plat = {"dazhongdp","elm","jd","meituan","meituan_tg","pinduoduo","suning","taobao","tmall","txd"};
//    public static String[] plat = {"secoo","kaola","jumei","miya","beibei","yunji","dangdang","guomei"};

//    public static String[] plat = {"jd","txd"};
//    public static String[] plat = {"secoo","kaola","jumei","miya","beibei","yunji","dangdang","guomei"};
//    public static String[] plat = {"pinduoduo","suning","taobao","tmall","jd"}; //,
//    public static String[] plat = {"secoo","kaola","jumei","miya","beibei","yunji","dangdang","guomei"};
//
//    public static String paths = "/dws-data/g_shop/2021/1/";
//    public static String paths = "/dws-data/split/split_data/2021/";


//    public static String paths = "/o2o-dataproces-group/he_xinhui/2020/12/qichezhijia/good_3/";

//    public static String[] plat = {"pinduoduo","suning","taobao","tmall","jd"};
//    public static String paths = "/o2o-dataproces-group/liu_jianlin/dws_data/2021/2/";
    public static String[] plat = {"taobao"};
    public static String paths = "/o2o-dataproces-group/zsc/test/taobao/2021/2/taobaoFinalData_orc/";
    /****************************************************************************************/
    //2019年618数据
//    public static String[] months = new String[]{"01","02","03","04","05","06","07","08","09","10","11","12"};
//    public static String[] months = new String[]{"07"};
    public static String month = "02";
//"01","02","03","04","05","06",suning
    public static HashMap map1 = new HashMap();


    public static void main(String[] args) {
//        map1.put("01","1");
//        map1.put("02","2");
//        map1.put("03","3");
//        map1.put("04","4");
//        map1.put("05","5");
//        map1.put("06","6");
//        map1.put("07","7");
//        map1.put("08","8");
//        map1.put("09","9");
//        map1.put("10","10");
//        map1.put("11","11");
//        map1.put("12","12");
//        String schem = "dbadmin";
//        String schem = "zf_test"; //店铺放到zf_test
//        String schem = "offline";
//        String schem = "activity";
//        String schem = "zf_tabletest";//小商品放到test_liu
//        String schem = "user_chen";//小商品放到test_liu
//        String schem = "detail";//小商品放到test_liu
//        String schem = "activity";//小商品放到test_liu
//        String schem = "user_liu";//小商品放到test_liu
        String schem = "test_liu";//小商品放到test_liu
//        String schem = "swb_schema";//小商品放到test_liu
//        String schem = "detail";//小商品放到test_liu
//        String schem = "test_zsc";//小商品放到test_liu
//        Connection con = GetConnectionzf("dbadmin", "Goal@Data@2018"); //dbadmin Goal@Data@2018
        Connection con = GetConnectionzf("sysadmin", "Bigdata@123"); //dbadmin Goal@Data@2018
        Statement statement = null;
        try {
            statement = con.createStatement();

                for (String pla : plat) {
                    String obs = "s3a:/";
                    //店铺
                        String path = obs + paths + pla +  "/" ;
                        String fordername = paths + pla +  "/" ;
                    //小平台单品
//                        String path = obs + paths + pla +  "/2/" ;
//                        String fordername = paths + pla +  "/2/" ;

//                        String path = obs + paths +map1.get(month)+"/"+ pla+"/";
//                        String fordername =  paths  +map1.get(month)+"/"+ pla+"/";
//                        String path = obs + paths +"/";
//                        String fordername =  paths +"";
//                    String orcSchema = obsUtils.getOrcSchema(path);

//                    String sql = obsUtils.sql(orcSchema, schem, pla, month, fordername);
//                    statement.executeUpdate(sql);

                    System.out.print("======================================================");
                }

        } catch (Exception e) {
            System.out.println(e);
            System.out.print("创建失败");
        }

    }

    public static Connection GetConnectionzf(String username, String passwd) {
        //定义驱动类。
        String driver = "org.postgresql.Driver";
//192.168.2.234
        //192.168.2.148
        Properties props = new Properties();
        props.setProperty("user", username);
        props.setProperty("password", passwd);
        String url = "jdbc:postgresql://" + "192.168.2.234" + ':'
                + "8000" + '/'
                + "postgres";
        Connection conn = null;
        try {
            //加载驱动。
            Class.forName(driver);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

        try {
            //创建连接。
            conn = DriverManager.getConnection(url, props);
            System.out.println("Connection succeed!");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return conn;
    }

}
